<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('systemManagement.loginName')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input :placeholder="$t('systemManagement.enterLoginNameFuzzyQuery')" v-model="queryParam.loginName"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('systemManagement.tenantType')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select v-model="queryParam.type" :placeholder="$t('systemManagement.pleaseTenantType')">
                    <a-select-option value="0">{{$t('systemManagement.freeTenant')}}</a-select-option>
                    <a-select-option value="1">{{$t('systemManagement.payingTenant')}}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('systemManagement.tenantStatus')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select v-model="queryParam.enabled" :placeholder="$t('systemManagement.pleaseStatus')">
                    <a-select-option value="1">{{$t('systemManagement.enable')}}</a-select-option>
                    <a-select-option value="0">{{$t('systemManagement.disable')}}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery">{{$t('systemManagement.query')}}</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">{{$t('systemManagement.reset')}}</a-button>
                </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="border-top: 5px">
          <a-button @click="handleAdd" type="primary" icon="plus">{{$t('systemManagement.newlAdded')}}</a-button>
          <a-dropdown>
            <a-menu slot="overlay">
              <a-menu-item key="1" @click="batchSetStatus(1)"><a-icon type="check-square"/>{{$t('systemManagement.enable')}}</a-menu-item>
              <a-menu-item key="2" @click="batchSetStatus(0)"><a-icon type="close-square"/>{{$t('systemManagement.disable')}}</a-menu-item>
            </a-menu>
            <a-button>
              {{$t('systemManagement.batchOperation')}}
              <a-icon type="down"/>
            </a-button>
          </a-dropdown>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            bordered
            size="middle"
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="scroll"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
            @change="handleTableChange">
            <span slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">{{$t('systemManagement.edit')}}</a>
            </span>
            <!-- 状态渲染模板 -->
            <template slot="customRenderType" slot-scope="type">
              <a-tag v-if="type==0">{{$t('systemManagement.freeTenant')}}</a-tag>
              <a-tag v-if="type==1" color="green">{{$t('systemManagement.payingTenant')}}</a-tag>
            </template>
            <template slot="customRenderEnabled" slot-scope="enabled">
              <a-tag v-if="enabled" color="green">{{$t('systemManagement.enable')}}</a-tag>
              <a-tag v-if="!enabled" color="orange">{{$t('systemManagement.disable')}}</a-tag>
            </template>
          </a-table>
        </div>
        <!-- table区域-end -->
        <tenant-modal ref="modalForm" @ok="modalFormOk"></tenant-modal>
      </a-card>
    </a-col>
  </a-row>
</template>
<!-- b y 7 5 2 7  1 8 9 2 0 -->
<script>
  import TenantModal from './modules/TenantModal'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import JInput from '@/components/jeecg/JInput'
  export default {
    name: "TenantList",
    mixins: [JeecgListMixin],
    components: {
      TenantModal,
      JInput
    },
    data() {
      return {
        labelCol: {
          span: 5
        },
        wrapperCol: {
          span: 18,
          offset: 1
        },
        queryParam: {
          loginName: '',
          type: '',
          enabled: ''
        },
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:40,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          { title:this.$t('systemManagement.loginName') , dataIndex: 'loginName', width: 100, align: "center"},
          { title:this.$t('systemManagement.userNumberLimit'), dataIndex: 'userNumLimit', width: 100, align: "center"},
          { title:this.$t('systemManagement.tenantType'),dataIndex: 'type',width:70,align:"center",
            scopedSlots: { customRender: 'customRenderType' }
          },
          { title:this.$t('systemManagement.tenantStatus'),dataIndex: 'enabled',width:70,align:"center",
            scopedSlots: { customRender: 'customRenderEnabled' }
          },
          { title:this.$t('systemManagement.creationTime'), dataIndex: 'createTimeStr', width: 100, align: "center"},
          { title:this.$t('systemManagement.expirationTime'), dataIndex: 'expireTimeStr', width: 100, align: "center"},
          { title:this.$t('systemManagement.description'), dataIndex: 'remark', width: 200, align: "center", ellipsis:true},
          {
            title:this.$t('systemManagement.operation'),
            dataIndex: 'action',
            scopedSlots: {customRender: 'action'},
            align: "center",
            width: 100
          }
        ],
        url: {
          list: "/tenant/list",
          batchSetStatusUrl: "/tenant/batchSetStatus"
        },
      }
    },
    created () {
    },
    methods: {
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>